package com.zdp.course.service;

import com.zdp.course.controller.CourseDto;
import com.zdp.course.mapper.CourseMapper;
import com.zdp.course.pojo.CourseDo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 类描述: 课程信息提供服务
 *
 * @author ZhhengDP
 * @since 2021/8/16
 */
@Service
public class CourseService {

    private CourseMapper courseMapper;

    @Value("${server.port}")
    private Integer courseServicePort = 0;

    @Autowired
    public CourseService(CourseMapper courseMapper){
        this.courseMapper = courseMapper;
    }

    public List<CourseDto> getCoursesByTeacherId(Integer teacherId){
        CourseDo temp = new CourseDo();
        temp.setTeacherId(teacherId);
        List<CourseDo> courses = courseMapper.select(temp);
        return courses.stream().map((course) -> {
            return new CourseDto(course,courseServicePort);
        }).collect(Collectors.toList());
    }
}
